package com.biglead.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.biglead.admin.mapper.PmsProductAttributeMapper;
import com.biglead.admin.mapper.ProductAttributeCategoryMapper;
import com.biglead.admin.pojo.PmsProductAttribute;
import com.biglead.admin.pojo.PmsProductAttributeCategory;
import com.biglead.admin.pojo.PmsProductAttributeCategoryItem;
import com.biglead.admin.pojo.PmsProductCategory;
import com.biglead.admin.service.PmsProductAttributeCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("productAttributeCategoryService")
public class PmsProductAttributeCategoryServiceImpl extends ServiceImpl<ProductAttributeCategoryMapper, PmsProductAttributeCategory> implements PmsProductAttributeCategoryService {
    @Autowired
    private ProductAttributeCategoryMapper productAttributeCategoryMapper;
    @Override
    public boolean create(String name) {
        PmsProductAttributeCategory productAttributeCategory = new PmsProductAttributeCategory();
        productAttributeCategory.setName(name);
        return this.save(productAttributeCategory);
    }

    @Override
    public boolean update(Long id, String name) {
        UpdateWrapper<PmsProductAttributeCategory> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id", id);
        PmsProductAttributeCategory productCategory = new PmsProductAttributeCategory();
        productCategory.setName(name);
        boolean i = this.update(productCategory, updateWrapper);
        return i;
    }

    @Override
    public boolean delete(Long id) {
        return this.removeById(id);
    }

    @Override
    public PmsProductAttributeCategory getItem(Long id) {
        return this.getById(id);
    }

    @Override
    public Page<PmsProductAttributeCategory> getListPage(Integer pageSize, Integer pageNum) {
        Page<PmsProductAttributeCategory> page = Page.of(pageNum, pageSize);
        //queryWrapper组装查询where条件
        LambdaQueryWrapper<PmsProductAttributeCategory> queryWrapper = new LambdaQueryWrapper<>();

        //发起查询
        this.page(page, queryWrapper);
        return page;
    }

    @Override
    public List<PmsProductAttributeCategoryItem> getListWithAttr() {
        return productAttributeCategoryMapper.getListWithAttr();
    }
}
